package com.acme.bankapp.service.bank;

import java.io.*;
import java.net.Socket;

/**
 * Created by anton on 8/22/14.
 */
public class BankClient {
    static void startClient() {
        try(Socket socket = new Socket("127.0.0.1", 5512)) {
            System.out.println("Connecting...");
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            BufferedReader console = new BufferedReader(new InputStreamReader(System.in));

            while(true) {
                String message = console.readLine();
                System.out.println(message + " entered");
                writer.write(message);
                writer.newLine();
                writer.flush();

                String line = null;
                while((line = reader.readLine()) != null) {
                    System.out.println(line);
//                    line = reader.readLine();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        startClient();
    }
}
